package kr.co.m2soft.model.page
{
	import flash.xml.XMLDocument;
	import flash.xml.XMLNode;
	
	import kr.co.m2soft.model.BaseModel;
	import kr.co.m2soft.model.CommonModel;
	import kr.co.m2soft.model.IBaseModelParser;
	import kr.co.m2soft.model.page.elements.CV;
	import kr.co.m2soft.model.page.elements.CY;
	import kr.co.m2soft.model.page.elements.DM;
	import kr.co.m2soft.model.page.elements.EP;
	import kr.co.m2soft.model.page.elements.HH;
	import kr.co.m2soft.model.page.elements.IM;
	import kr.co.m2soft.model.page.elements.LL;
	import kr.co.m2soft.model.page.elements.LN;
	import kr.co.m2soft.model.page.elements.PL;
	import kr.co.m2soft.model.page.elements.PO;
	import kr.co.m2soft.model.page.elements.RA;
	import kr.co.m2soft.model.page.elements.RR;
	import kr.co.m2soft.model.page.elements.SC;
	import kr.co.m2soft.model.page.elements.TX;
	
	import mx.collections.ArrayCollection;

	public class PG extends BaseModel implements IBaseModelParser
	{
		private var commonModel:CommonModel;
		private var _elements:ArrayCollection;
		private var _no:int;
		private var _si:String = "A4";
		private var _or:String = "p";
		private var _wd:Number;
		private var _ht:Number;
		
		public function PG()
		{
		}
		public function parser():void
		{
			_elements = new ArrayCollection();
			
			for each(var item:XML in dataProvider.children()){
				var o:*;
				var nodeName:String = new XMLDocument(item.toXMLString()).firstChild.nodeName;
				
				_si = dataProvider.hasOwnProperty("@si") ? dataProvider.@si : _si;
				_or = dataProvider.hasOwnProperty("@or") ? dataProvider.@or : _or;
				_wd = dataProvider.hasOwnProperty("@wd") ? dataProvider.@wd : _wd;
				_ht = dataProvider.hasOwnProperty("@ht") ? dataProvider.@ht : _ht;
				//_no = commonModel.mml.body.elements.length;
				switch(nodeName){
					case "TX" : o = new TX(); break;
					case "SC" : o = new SC(); break;
					case "LN" : o = new LN(); break;
					case "CV" : o = new CV(); break;
					case "LL" : o = new LL(); break;
					case "RA" : o = new RA(); break;
					case "RR" : o = new RR(); break;
					case "EP" : o = new EP(); break;
					case "DM" : o = new DM(); break;
					case "PL" : o = new PL(); break;
					case "PO" : o = new PO(); break;
					case "HH" : o = new HH(); break;
					case "CY" : o = new CY(); break;
					case "IM" : o = new IM(); break;
				}
				if(o){
					o.dataProvider = item;
					o.parser();
					_elements.addItem(o);
				}
			}
			
		}
		public function get elements():ArrayCollection
		{
			return _elements;
		}

		public function set elements(value:ArrayCollection):void
		{
			_elements = value;
		}

		public function get no():int
		{
			return _no;
		}

		public function set no(value:int):void
		{
			_no = value;
		}
		
		[Inspectable(enumeration="A1,A2,A3,A4,A5,B3,B4,B5,LETTER,136,80,CUSTOM", defaultValue="A4" )]
		public function get si():String
		{
			return _si;
		}
		[Inspectable(enumeration="A1,A2,A3,A4,A5,B3,B4,B5,LETTER,136,80,CUSTOM", defaultValue="A4" )]
		public function set si(value:String):void
		{
			_si = value;
		}
		[Inspectable(enumeration="p,l", defaultValue="p" )]
		public function get or():String
		{
			return _or;
		}

		public function set or(value:String):void
		{
			_or = value;
		}

		public function get wd():Number
		{
			return _wd;
		}

		public function set wd(value:Number):void
		{
			_wd = value;
		}

		public function get ht():Number
		{
			return _ht;
		}

		public function set ht(value:Number):void
		{
			_ht = value;
		}


	}
}